"""
author: Jackson Black
time: 2023-08-20 13-39-08 
"""


class Student(object):
    # __slots__的限定只对当前类的对象生效，对子类并不起任何作用。
    # 限定 Student 对象自能绑定  '_name', '_age', '_gender' 属性
    __slots__ = ('_name', '_age', '_gender')

    def __init__(self, name, age, gender):
        self._name = name
        self._age = age
        self._gender = gender

    # get方法访问属性
    @property
    def name(self):
        return self._name

    @property
    def age(self):
        return self._age

    @property
    def gender(self):
        return self._gender

    # set方法设置属性的值
    @name.setter
    def name(self, name):
        self._name = name

    @age.setter
    def age(self, age):
        self._age = age

    @gender.setter
    def gender(self, gender):
        self._gender = gender

    # 静态方法：从属于类
    @staticmethod
    def teacher_name(name):
        print(f"My teacher is {name}")

    # 类方法
    @classmethod
    def get_student_object(cls):
        return cls("Mike", 22, "male")

    def speak(self):
        print(f'My name is {self._name}, a {self._age} years old boy.')

    def __run(self):
        print("私有方法")


def test_student(name, age, gender):
    student = Student(name, age, gender)
    print(student)
    student.speak()
    # 调用get方法
    print(student.name)
    # 调用set方法
    student.age = 32
    print(student.age)
    # 调用静态方法
    student.teacher_name("Mary")
    Student.teacher_name("Mary")
    # 调用类方法
    s = Student.get_student_object()
    print(f'name={s.name},age={s.age},gender={s.gender}')


if __name__ == "__main__":
    test_student("Black", 22, "male")
